<template>
  <div class="page-article" v-if="model">
    <div class="d-flex py-3 px-2">
      <div class="iconfont icon-icon_back text-blue"></div>
        <strong class="flex-1 text-ellipsis mr-1 text-blue">
          {{model.title}}
        </strong>
        <div class="text-grey fs-xs">
          2020-09-02
        </div>
    </div>

    <div class="px-3 body fs-lg" v-html="model.body"></div>
    <div class="px-3 border-top py-3">
      <div class="d-flex ai-center">
        <i class="iconfont icon-lianjie"></i>
        <strong class="text-blue fs-lg ml-2">相关资讯</strong>
      </div>
      <div class="pt-2 fs-lg">
        <router-link
            class="py-1"
            tag="div"
            :to="`/articles/${item._id}`"
            v-for="item in model.related"
            :key="item._id">
          {{item.title}}
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Article",
  props: {
    id: {required: true}
  },
  data() {
    return {
      model: null
    }
  },
  watch: {
    /*id: 'fetch',*/
    // 监听页面变化
    id() {
      this.fetch()
    }
  },
  created(){
    this.fetch()
  },
  methods: {
    // 获取文章详情
    async fetch() {
      const res = await this.$http.get(`articles/${this.id}`)
      this.model = res.data
    }
  }
}
</script>

<style lang="scss">
.page-article {
  .icon-icon_back{
    font-size: 1.692rem;
  }
  .body {
     img{
       max-width: 100%;
       height: auto;
     }
    iframe {
      width: 100%;
      height: auto;
    }
  }
}
</style>